<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>求某个字段出现的次数和位置</title>
		<script type="text/javascript">
			var str = 'abcoopopopotttotp';
			var count = 0;
			var index = str.indexOf('o');
			
			while(index != -1) {
				//字符串存在这个字符
				count++;
				console.log(index);
				//然后从这个字符的位置后面+1，再3继续寻找
				index = str.indexOf('o',index + 1);
			}
			console.log('o出现的次数:' + count);
		</script>
	</head>
	<body>
	</body>
</html>
